@extends('template.adminpage')
@section('content')
<ol class="breadcrumb">
    <li class="active">Laporan Bonus</li>
</ol>


<div class="container-black">
    <div class="row" style="margin-top:5px">
        <div class="col-md-7">
            <label><u>Laporan Bonus</u></label>
        </div>
        <div class="col-md-5">
            <form action="bonusperbulan" method="POST">
                <div class="input-group" >
                    <select class="form-control" name="bulan" style="height:30px">
                        <?php
                        $bulan = array('Januari' => 1, 'Februari' => 2, 'Maret' => 3, 'April' => 4, 'Mei' => 5, 'Juni' => 6, 'Juli' => 7, 'Agustus' => 8, 'September' => 9, 'Oktober' => 10, 'November' => 11, 'Desember' => 12);
                        ;
                        foreach ($bulan as $key => $val) {
                            if ($val == $b) {
                                echo '<option value="' . $val . '" selected>' . $key . '</option>';
                            } else {
                                echo '<option value="' . $val . '">' . $key . '</option>';
                            }
                        }
                        ?>
                    </select>
                    <span class="input-group-btn">

                        <select class="form-control" name="tahun" style="width:100px;height:30px">
                            <option value="">Tahun</option>
                            <?php
                            for ($i = 2011; $i < 2033; $i++) {
                                if ($i == $t) {
                                    echo '<option value="' . $i . '" selected>' . $i . '</option>';
                                } else {
                                    echo '<option value="' . $i . '">' . $i . '</option>';
                                }
                            }
                            ?>
                        </select>
                    </span>
                    <span class="input-group-btn">
                        <button class="btn btn-dark" type="submit" style="height:30px"><span class="glyphicon glyphicon-search"></span> Lihat</button>
                    </span>
                </div><!-- /input-group -->
            </form>
        </div>
    </div>	
    <legend style="margin-bottom:0px; margin-top:5px"></legend>
    <h3 align="center">Laporan bonus bulan <?php
                            foreach ($bulan as $key => $val) {
                                if ($val == $b) {
                                    echo $key . ' ' . $t;
                                }
                            }
                            ?></h3>
    <label><u>Summary</u></label>

    <div class="row" style="margin-top:10px">
        <div class="col-md-8 col-md-offset-2">

            <div class="row">
                <div class="col-lg-5">
                    <label>Total Bonus Order </label>
                </div>
                <div class="col-lg-5">
                    <label>Rp. {{number_format($jumlahbonusorder,0,".",".")}},00</label>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-5">
                    <label>Total Bonus Referal </label>
                </div>
                <div class="col-lg-5">
                    <label>Rp. {{number_format($jumlahbonusref,0,".",".")}},00</label>
                </div>
            </div>
            <br>

        </div> 
    </div>   
    <label><u>Daftar agen</u></label>
    <br>
    <form action="bonussearch" method="POST">

        <div class="row">
            <div class="col-md-9">
                <div class="col-lg-3">
                    <label>Kata kunci</label>
                </div>
                <div class="col-lg-3">
                    <input type="text"  class="form-control" placeholder="Kata kunci" name="keyword" style="height:30px" /></input>
                </div>
                <div class="col-lg-3 col-md-offset-1">
                    <select name="filterby" class="form-control" style="height:30px" >
                        <option value="agencode">Kode agen</option>
                        <option value="referalcode">Kode referal (sponsor)</option>
                        <option value="agenname">Nama agen</option>
                    </select>
                </div>
            </div>
        </div>
        <br>
        <div class="row">
            <div class="col-md-9">
                <div class="col-md-3 col-md-offset-3">
                    <button class="btn btn-sm btn-dark" type="submit" style="height:30px"><span class="fa fa-search"></span> Tampilkan</button>
                </div>
            </div>
        </div>


    </form>
<a href="{{URL::to('/report/bonusexportxls')}}" target="_blank"><button class="btn btn-xs btn-info pull-right" ><span class="fa fa-print"></span> Export excel</button></a><br>
    <?php
    $limit = 10;
    if (Input::get('page') == 0 OR Input::get('page') == 1) {
        $no = 1;
    } else {
        $no = ((Input::get('page') - 1) * $limit) + 1;
    }
    ?>
    <table class="table table-bordered table-hover" style="margin-top:5px">
        <thead>
            <tr>
                <th>No</th>
                <th>Kode agen</th>
                <th>Nama agen</th>
                <th>Referal</th>
                <th>Tanggal Transaksi</th>
                <th>Bonus Order</th>
                <th>Bonus Referal</th>
                <th>Status</th>
                <!--<th>Aksi</th>-->
            </tr>
        </thead>
        <tbody>
            <tr>

                @foreach($dataagen as $agen)
                <?php
                $refc = DB::table('sys_agen')
                        ->where('agen_id', $agen->agen_sponsor_id)
                        ->count();
                $ref = DB::table('sys_agen')
                        ->where('agen_id', $agen->agen_sponsor_id)
                        ->first();
                if ($refc==0) {
                    $code = 'Perusahaan';
                } else {
                    $code = $ref->agen_code;
                }

                $agenacc = DB::table('sys_account_agen')
                        ->where('account_agen_id', $agen->agen_id)
                        ->count();
                
                

                
                ?>
                <td>{{$no}}</td>
                <td>{{$agen->agen_code}}</td>
                <td>{{$agen->member_name}}</td>
                <td>{{$code}}</td>
                <td>{{date("d-M-Y",strtotime($agen->bonus_log_date))}}</td>
                <td>Rp. {{number_format($agen->bonus_log_order,0,".",".")}},00</td>
                <td>Rp. {{number_format($agen->bonus_log_referal,0,".",".")}},00</td>
                <td>{{$agen->member_status}}</td>

                <!--<td style="width:150px"><a data-toggle="modal" data-target="#detail{{$agen->agen_id}}" title="Agen Detail"><button class="btn btn-xs btn-dark" ><span class="fa fa-file"></span></button></a></td>-->
                <?php $no++; ?>

            </tr>

            @endforeach
        </tbody>
<!--        <tr>
            
            <td colspan="5" style="text-align: right">TOTAL</td>
            <td></td>
            <td></td>
        </tr>-->

    </table>
    <div class="text-right"><?php echo $dataagen->links(); ?></div>
</div>

@stop
@stop